package zelix.hack.hacks;

import java.lang.reflect.Field;

import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.value.Mode;
import zelix.value.ModeValue;
import net.minecraft.network.play.client.CPacketPlayer;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import zelix.utils.Wrapper;
import zelix.utils.system.Connection;

public class AntiFall extends Hack {
	public ModeValue mode;

	public AntiFall() {
		super("NoFall", HackCategory.PLAYER);

		this.mode = new ModeValue("Mode", new Mode("AAC", true), new Mode("Simple", false));
		this.addValue(mode);
	}

	@Override
	public String getDescription() {
		return "Gives you zero damage on fall.";
	}

	@Override
	public void onClientTick(ClientTickEvent event) {
		if (mode.getMode("Simple").isToggled()) {
			if (Wrapper.INSTANCE.player().fallDistance > 2)
				Wrapper.INSTANCE.sendPacket(new CPacketPlayer(true));
		}
		super.onClientTick(event);
	}
	@Override
	public boolean onPacket(Object packet, Connection.Side side) {
		if (side == Connection.Side.OUT) {
			if (packet instanceof CPacketPlayer) {
				final CPacketPlayer p = (CPacketPlayer) packet;

				if (mode.getMode("AAC").isToggled()) {
					Field field = ReflectionHelper.findField(CPacketPlayer.class,
							new String[] { "onGround", "field_149474_g" });
					try {

						if (!field.isAccessible()) {
							field.setAccessible(true);
						}

						field.setBoolean(p, true);

					} catch (Exception e) {
						//////////System.out.println(e);
					}
				}
			}

		}
		return true;
	}
}
